package com.itic.web.pay.common;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.ht.mem.member.persistence.model.WebMember;
import com.itic.ht.mem.memberdetail.persistence.model.WebMemberDetail;
import com.itic.ht.mem.mtype.persistence.model.WebmType;
import com.itic.ht.mem.performance.persistence.model.Performance;
import com.itic.ht.mem.performance.persistence.model.Performancedetail;

public class PayCommon {
	public static WebMember getNewWebMember(WebmType webmType, WebMember webMember,
		Performancedetail performancedetail) {
		webMember.setMtime(new Date());
		webMember.setCategory(webmType.getId());
		webMember.setAccount(performancedetail.getAccount());
		return webMember;
	}
	public static WebMemberDetail getNewMemberDetail(WebMember webMember,WebmType webmType,WebMemberDetail memberDetail ) throws ParseException{
		Date date = new Date();
	//	WebMemberDetail memberDetail = new WebMemberDetail();
		webMember.setCategory(webmType.getId());
   	 	webMember.setMtime(date);
	   	//判断用户会员的期限是永久还是月数
	   	 if("-1".equals(webmType.getLongTime())){
	   		 memberDetail.setExpireTime(new SimpleDateFormat("yyyy-MM-dd").parse("2099-12-31"));
	   	 }else{
	   		 //根据购买月数增加用户过期时间
	   		 Calendar now = Calendar.getInstance();
	   		 now.add(Calendar.MONTH, webmType.getLongTime());
	   		 memberDetail.setExpireTime(now.getTime());
	   	   }
	   	 memberDetail.setCategory(webmType.getId());
	   	 memberDetail.setMtime(date);
		return memberDetail;
	}
	
	public static Performance getNewPerformance(WebMember member,WebmType webmType,BigDecimal lelel){
		Performance performance = new Performance();
		Date date = new Date();
		performance.setCtime(date);
		performance.setMtime(date);
		performance.setEffective(DBConst.TRUE);
		performance.setMemAccount(member.getAccount());
		performance.setIncome(webmType.getPrice().multiply(lelel).doubleValue());
		return performance;
	}
	public static Performancedetail getNewPerformancedetail(WebMember member,WebmType webmType,BigDecimal lelel){
		Performancedetail performancedetail = new Performancedetail();
		performancedetail.setAccount(member.getAccount());
		performancedetail.setIncome(webmType.getPrice().multiply(lelel).doubleValue());
		performancedetail.setLevel(DBConst.ONE_LEVEL);
		return performancedetail;
	}
	
}
